package cn.edu.nit.sys.controller;

import cn.edu.nit.sys.config.OperationAnnotation;
import cn.edu.nit.sys.entity.Notice;
import cn.edu.nit.sys.mapper.NoticeMapper;
import cn.edu.nit.sys.service.NoticeService;
import cn.edu.nit.sys.utils.R;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @PostMapping
    @OperationAnnotation(description = "新增通知", opType = "新增")
    public R addNotice(@RequestBody Notice notice) {
        return ObjectUtils.isNotEmpty(noticeService.addNotice(notice)) ? R.ok("添加成功") : R.error("添加失败");
    }

    @GetMapping
    public R getNoticeList(String title, String start, String end, Page<Notice> page) {
        return noticeService.getNoticeList(title, start, end, page);
    }

    @GetMapping("/detail/{id}")
    public R getNoticeDetail(@PathVariable("id") String id) {
        return noticeService.getDetail(id);
    }

    @PutMapping
    @OperationAnnotation(description = "修改通知", opType = "修改")
    public R updateNotice(@RequestBody Notice notice) {
        return noticeService.updateNotice(notice);
    }

    @DeleteMapping("/{id}")
    public R delNotice(@PathVariable("id")String id) {
        return noticeService.delNotice(id);
    }
}
